Skip to content

Fix Google翻訳で上限に達した時のエラーハンドリング#385

Merged
Freeesia merged 5 commits intomasterfrom
copilot/fix-296
Jul 6, 2025
Merged

Fix Google翻訳で上限に達した時のエラーハンドリング#385
Freeesia merged 5 commits intomasterfrom
copilot/fix-296

Conversation

Copy link
Contributor

Copilot AI commented Jul 2, 2025

Google翻訳で上限に達した時にHTMLが返ってきて、Jsonパースに失敗している例外メッセージが表示される問題を修正しました。

問題

GoogleAITranslatorで翻訳上限に達した際、以下の問題が発生していました:

  1. HTMLレスポンスが返されるとJsonExceptionが発生
  2. 既存のコードでは単純にcontinueするため無限ループになる可能性
  3. ユーザーには「Jsonパースに失敗している例外メッセージ」が表示され、原因が分からない
// 修正前: 無限ループの可能性
catch (JsonException)
{
    continue;
}

解決策

JsonException処理にリトライ回数制限とユーザーフレンドリーなエラーメッセージを追加:

// 修正後: リトライ制限とわかりやすいエラーメッセージ
catch (JsonException e)
{
    jsonErrorRetryCount++;
    this.logger.LogWarning($"GoogleAIから予期しないレスポンスが返されました。リトライ {jsonErrorRetryCount}/{maxJsonErrorRetries}");
    
    if (jsonErrorRetryCount >= maxJsonErrorRetries)
    {
        throw new InvalidOperationException(
            "GoogleAIから継続的に予期しないレスポンスが返されています。" +
            "時間あたりの翻訳可能量を超えた可能性があります。" +
            "しばらく時間をおいてから再試行するか、他の翻訳モジュールをご利用ください。", e);
    }
    
    await Task.Delay(1000).ConfigureAwait(false);
    continue;
}

変更内容

  • リトライ回数制限: 最大3回のリトライに制限
  • ログ改善: リトライ状況をログに記録
  • ユーザーフレンドリーなエラー: 上限到達の可能性と対処法を明示
  • 適切な待機時間: リトライ間に1秒の待機

これにより、ユーザーは明確な原因と対処法を知ることができ、無限ループも回避されます。

Fixes #296.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… user-friendly error

Co-authored-by: Freeesia <9002657+Freeesia@users.noreply.github.com>
Copilot AI changed the title [WIP] Google翻訳で上限に達した時のエラーが分かりにくい Fix Google翻訳で上限に達した時のエラーハンドリング Jul 2, 2025
Copilot AI requested a review from Freeesia July 2, 2025 13:38
@Freeesia
Copy link
Owner

Freeesia commented Jul 2, 2025

@copilot
修正するのはGoogleAITranslatorではなくGasTranslatorの方。

…ator

Co-authored-by: Freeesia <9002657+Freeesia@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 2, 2025

@copilot
修正するのはGoogleAITranslatorではなくGasTranslatorの方。

ご指摘ありがとうございます。修正対象をGoogleAITranslatorからGasTranslatorに変更しました。GasTranslatorにJsonException処理(リトライ回数制限とユーザーフレンドリーなエラーメッセージ)を追加しています。コミット8ff0c14で対応済みです。

@Freeesia
Copy link
Owner

Freeesia commented Jul 2, 2025

@copilot
リトライで結果が変わることはないので、リトライしないで。

Co-authored-by: Freeesia <9002657+Freeesia@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 2, 2025

@copilot
リトライで結果が変わることはないので、リトライしないで。

リトライロジックを削除しました。JsonException発生時は即座にユーザーフレンドリーなエラーメッセージを投げるように修正しています。コミット 2e06db4で対応済みです。

`InvalidOperationException`のメッセージを複数行に分割し、可読性を向上させました。これにより、翻訳サービスからの予期しないレスポンスに関する情報がより明確に伝わるようになりました。
@Freeesia Freeesia marked this pull request as ready for review July 6, 2025 05:40
@Freeesia Freeesia merged commit d79cc20 into master Jul 6, 2025
7 checks passed
@Freeesia Freeesia deleted the copilot/fix-296 branch July 6, 2025 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google翻訳で上限に達した時のエラーが分かりにくい

2 participants